//
//  ASResearchCell.m
//  AttendenceSys
//
//  Created by 窦芳俊 on 16/4/13.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "ASResearchCell.h"

@implementation ASResearchCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        CGFloat fontSize = 16;
        CGFloat padding = 17;
        CGFloat bgWidth = [[UIScreen mainScreen] bounds].size.width;
        
        _researchName = [[UILabel alloc] initWithFrame:CGRectZero];
        _researchName.frame = CGRectMake(padding, 12, bgWidth - 2 * padding, 15);
        [_researchName setBackgroundColor:[UIColor clearColor]];
        [_researchName setTextColor:RGB(51, 51, 51)];
        [_researchName setFont:[UIFont systemFontOfSize:fontSize]];
        [self.contentView addSubview:_researchName];
        
        _researchType = [[UILabel alloc] initWithFrame:CGRectZero];
        _researchType.frame = CGRectMake(padding,
                                         _researchName.frame.origin.y + _researchName.frame.size.height + 5,
                                         bgWidth - 2 * padding,
                                         15);
        [_researchType setBackgroundColor:[UIColor clearColor]];
        [_researchType setTextColor:RGB(51, 51, 51)];
        [_researchType setFont:[UIFont systemFontOfSize:fontSize]];
        [self.contentView addSubview:_researchType];
        
        _researchTime = [[UILabel alloc] initWithFrame:CGRectZero];
        _researchTime.frame = CGRectMake(padding,
                                         _researchType.frame.origin.y + _researchType.frame.size.height + 5,
                                         bgWidth - 2 * padding,
                                         15);
        [_researchTime setBackgroundColor:[UIColor clearColor]];
        [_researchTime setTextColor:RGB(51, 51, 51)];
        [_researchTime setFont:[UIFont systemFontOfSize:fontSize]];
        [self.contentView addSubview:_researchTime];
        
        /******************************************************************0523
        _researchLevel = [[UILabel alloc] initWithFrame:CGRectZero];
        _researchLevel.frame = CGRectMake(padding,
                                          _researchTime.frame.origin.y + _researchTime.frame.size.height + 5,
                                          bgWidth - 2 * padding,
                                          15);
        [_researchLevel setBackgroundColor:[UIColor clearColor]];
        [_researchLevel setTextColor:RGB(51, 51, 51)];
        [_researchLevel setFont:[UIFont systemFontOfSize:fontSize]];
        [self.contentView addSubview:_researchLevel];
        
        _researchComment = [[UILabel alloc] initWithFrame:CGRectZero];
        _researchComment.frame = CGRectMake(padding,
                                          _researchLevel.frame.origin.y + _researchLevel.frame.size.height + 5,
                                          bgWidth - 2 * padding,
                                          15);
        [_researchComment setBackgroundColor:[UIColor clearColor]];
        [_researchComment setTextColor:RGB(51, 51, 51)];
        [_researchComment setFont:[UIFont systemFontOfSize:fontSize]];
        [self.contentView addSubview:_researchComment];
        
        _researchDesc = [[UILabel alloc] initWithFrame:CGRectZero];
        _researchDesc.frame = CGRectMake(padding,
                                          _researchComment.frame.origin.y + _researchComment.frame.size.height + 5,
                                          bgWidth - 2 * padding,
                                          15);
        [_researchDesc setBackgroundColor:[UIColor clearColor]];
        [_researchDesc setTextColor:RGB(51, 51, 51)];
        [_researchDesc setFont:[UIFont systemFontOfSize:fontSize]];
        [self.contentView addSubview:_researchDesc];
        
        // firstImage
        _firstImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        _firstImage.frame = CGRectMake(padding,
                                       _researchDesc.frame.origin.y + _researchDesc.frame.size.height + 10,
                                       kResearchImageWidth,
                                       kResearchImageHeight);
        //_firstImage.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_firstImage];
        
        // secondImage
        _secondImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        _secondImage.frame = CGRectMake(padding * 2 + kResearchImageWidth,
                                        _researchDesc.frame.origin.y + _researchDesc.frame.size.height + 10,
                                        kResearchImageWidth,
                                        kResearchImageHeight);
        //_secondImage.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_secondImage];
        
        // thirdImage
        _thirdImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        _thirdImage.frame = CGRectMake(padding * 3 + kResearchImageWidth * 2,
                                       _researchDesc.frame.origin.y + _researchDesc.frame.size.height + 10,
                                       kResearchImageWidth,
                                       kResearchImageHeight);
        //_thirdImage.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_thirdImage];
        
        // fourthImage
        _fourthImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        _fourthImage.frame = CGRectMake(padding * 4 + kResearchImageWidth * 3,
                                        _researchDesc.frame.origin.y + _researchDesc.frame.size.height + 10,
                                        kResearchImageWidth,
                                        kResearchImageHeight);
        //_fourthImage.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_fourthImage];
        
        ************************************************************************/
        
        // bottom line
        UIImageView* bottomLineView = [[UIImageView alloc] initWithFrame:CGRectMake(padding,
                                                                                    kResearchCellHeight - 1,
                                                                                    bgWidth - padding * 2,
                                                                                    1)];
        [bottomLineView setBackgroundColor:RGB(221, 221, 221)];
        [self.contentView addSubview:bottomLineView];
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

- (void)updateResearchCellStatus:(ASResearchInfo *)info rTypeInfo:(ASResearchTypeInfo *)tInfo
{
    //_researchName.text = @"标题: 如何把APP做好？";    //! 科研名称
    //_researchType.text = @"类型: 论文";    //! 科研类型（论文，专著，项目，专利，其它）
    //_researchTime.text = @"时间: 2016-04-13";    //! 科研时间
    //_researchLevel.text = @"科研级别: 国家级";   //! 科研级别（国家级，省部级，校级，院级）
    //_researchComment.text = @"科研备注: 软件开发描述指导"; //! 科研备注
    //_researchDesc.text = @"科研简介: 合理运用开发工具，团队合作，共渡难关";    //! 科研简介
    
    //_firstImage.image = [UIImage imageNamed:@"ic_call_activited"];
    //_secondImage.image = [UIImage imageNamed:@"ic_call_activited"];
    //_thirdImage.image = [UIImage imageNamed:@"ic_call_activited"];
    //_fourthImage.image = [UIImage imageNamed:@"ic_call_activited"];
    
    // 这里的展示需要根据类型做对应展示
    if ([tInfo.researchSubjectName isEqualToString:@"论文"])
    {
        [self showPaper:info];
    }
    else if ([tInfo.researchSubjectName isEqualToString:@"专著"])
    {
        [self showMonograph:info];
    }
    else if ([tInfo.researchSubjectName isEqualToString:@"项目"])
    {
        [self showProject:info];
    }
    else if ([tInfo.researchSubjectName isEqualToString:@"专利"])
    {
        [self showPatent:info];
    }
    else if ([tInfo.researchSubjectName isEqualToString:@"其它"])
    {
        [self showOther:info];
    }
}

- (void)showPaper:(ASResearchInfo *)info
{
    _researchName.text = [NSString stringWithFormat:@"名称: %@", info.researchA];
    _researchType.text = [NSString stringWithFormat:@"时间: %@", info.researchC];
    _researchTime.text = [NSString stringWithFormat:@"描述: %@", info.researchF];
}

- (void)showMonograph:(ASResearchInfo *)info
{
    _researchName.text = [NSString stringWithFormat:@"名称: %@", info.researchA];
    _researchType.text = [NSString stringWithFormat:@"出版社名称: %@", info.researchC];
    _researchTime.text = [NSString stringWithFormat:@"描述: %@", info.researchF];
}

- (void)showProject:(ASResearchInfo *)info
{
    _researchName.text = [NSString stringWithFormat:@"名称: %@", info.researchA];
    _researchType.text = [NSString stringWithFormat:@"时间: %@", info.researchC];
    _researchTime.text = [NSString stringWithFormat:@"描述: %@", info.researchG];
}

- (void)showPatent:(ASResearchInfo *)info
{
    _researchName.text = [NSString stringWithFormat:@"名称: %@", info.researchB];
    _researchType.text = [NSString stringWithFormat:@"级别: %@", info.researchC];
    _researchTime.text = [NSString stringWithFormat:@"描述: %@", info.researchE];
}

- (void)showOther:(ASResearchInfo *)info
{
    _researchName.text = [NSString stringWithFormat:@"名称: %@", info.researchA];
    _researchType.text = [NSString stringWithFormat:@"时间: %@", info.researchB];
    _researchTime.text = [NSString stringWithFormat:@"描述: %@", info.researchC];
}

@end





